<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>绝对定位使盒子居中</title>
    <style>
        .box{
            /*绝对定位*/
            position: absolute;
            left: 50%;
            top: 50%;

            /*位移*/
            transform:translate(-50%,-50%); /*自己宽高的一半*/

            width: 400px;
            height: 300px;
            background-color: palegoldenrod;
        }
    </style>
</head>
<body>
    <div class="box"></div>

</body>
</html>